package de.hhkk.controller;

import de.hhkk.main.Main;
import de.hhkk.model.auswertung.AuswertungService;
import de.hhkk.model.kursverwaltung.KursService;
import de.hhkk.model.stammdaten.StammdatenService;
import de.hhkk.model.terminverwaltung.TerminService;

public final class NavigationController
{

    private Object[]                    stack;
    private int                         zst;
    private int                         max;
    private static NavigationController instance = new NavigationController();

    public NavigationController()
    {
        instance = this;
        max = 3;
        this.stack = new Object[max];
        zst = 0;
        clearModel();
    }

    public void push(Object x)
    {
        Main.loescheStatusListe();
        if (!isFull())
        {
            stack[zst] = x;
            zst++;
        }
    }

    private void clearModel()
    {
        StammdatenService.getInstance().clear();
        TerminService.getInstance().clear();
        KursService.getInstance().clear();
        AuswertungService.getInstance().clear();
    }

    public void pop()
    {
        if (!isEmpty())
            zst--;
    };

    public Object top()
    {
        if (isEmpty())
            return null;
        else
            return stack[zst - 1];
    }

    public boolean isEmpty()
    {
        return (zst == 0);
    };

    public boolean isFull()
    {
        return (zst == max);
    };

    public int depth()
    {
        return zst;
    };

    public static NavigationController getInstance()
    {
        if (instance == null)
        {
            instance = new NavigationController();
        }
        return instance;
    }
    
    public void clear()
    {
        Main.loescheStatusListe();
        instance = null;
    }
}
